class MoviesController < ApplicationController
  before_filter :find_on_show_movies, :only => [:show, :index]
  before_filter :find_replies,:only => [:show]
  
  def index
  end
  
  def show
    @movie = Movie.find(params[:id])
    render 'movies/layout'
  end
  
  def create
    begin
      @movie = Movie.create!(params[:movie])
      puts "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"
      puts @movie.id
    rescue Exeption => e
        flash[:notice] = "Movie save false !"
        render :layout => 'layouts/admin_layout'
        render :action => :new
    end
    attachment = MoviePic.batch_create(:attachments => params[:movie_pics], :movie_id => @movie.id)
    if attachment[:exception] == "true"
      flash[:notice] = attachment[:flash]
      render :action => :new, :layout => 'layouts/admin_layout'   
    else
      flash[:notice] = "ok"
      redirect_to :action => :show ,:id => @movie.id, :layout => 'layouts/admin_layout'
    end
  end
  
  
  def destroy
    
  end
  
  
  private
  
  def find_on_show_movies
    @movies = Movie.find_all_by_show_status('on')
  end
  
  def find_replies
    @replies = Reply.paginate_by_movie_id params[:id], :page => 1
  end
  
  
end
